package com.lsa.letcode.the19.removeNthAtEnd;

import org.junit.Assert;
import org.junit.Test;

import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.ListNode;

public class TestRemoveNthAtEnd extends LetCodeTestBase{
	@Test
	public void test(){
		Assert.assertTrue(areEqual(asList(1,2,3),asList(1,2,3)));
		Assert.assertTrue(areEqual(asList(1,2),asList(1,2)));
		Assert.assertTrue(areEqual(asList(1),asList(1)));
		Assert.assertFalse(areEqual(asList(1,2,3),asList(1,2)));
		Assert.assertFalse(areEqual(asList(1,2),asList(1,2,3)));
//		System.out.println(asList(1,2,3).toString());
		
		Solution s = new Solution();
		test(s, asList(1), 1, asList());
		test(s, asList(1,2), 1, asList(1));
		test(s, asList(1,2), 2, asList(2));
		test(s, asList(1,2,3,4,5), 1, asList(1,2,3,4));
		test(s, asList(1,2,3,4,5), 2, asList(1,2,3,5));
		test(s, asList(1,2,3,4,5), 3, asList(1,2,4,5));
		test(s, asList(1,2,3,4,5), 4, asList(1,3,4,5));
		test(s, asList(1,2,3,4,5), 5, asList(2,3,4,5));
		test(s, asList(1,2,3,4,5), 6, asList(1,2,3,4,5));
		test(s, asList(1,2,3,4,5), 0, asList(1,2,3,4,5));
		test(s, asList(), 0, asList());
		test(s, asList(), 10, asList());
	}

	private void test(Solution s, ListNode input, int no, ListNode expected) {
		ListNode actual = s.removeNthFromEnd(input, no);
		Assert.assertTrue(String.format("expect %s actual %s", expected, actual), areEqual(expected,actual));
	}
}